package com.pes.arcww.form;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name="ITEMS")
public class Items implements Comparable<Items>, Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "ITE_ID", unique = true)
	@GeneratedValue
	private Integer ite_id;
	
	@Column(name = "ITE_DESCRIPTION", length = 500)
	private String description;
	
	@Column(name = "ITE_ISCORRECT")
	private Boolean isCorrect;
	
	@ManyToOne(fetch = FetchType.EAGER, optional=true)
	@JoinColumn(name = "QUE_ID_FK", nullable = false)
	private Questions question;
	
	@OneToMany(mappedBy = "item")
	@LazyCollection(LazyCollectionOption.FALSE)
	private Collection<ExamsItems> examItemsList = new ArrayList<ExamsItems>();

	public Integer getId() {
		return ite_id;
	}

	public void setId(Integer ite_id) {
		this.ite_id = ite_id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Boolean getIsCorrect() {
		return isCorrect;
	}

	public void setIsCorrect(Boolean isCorrect) {
		this.isCorrect = isCorrect;
	}
	
	public Questions getQuestion() {
		return question;
	}

	public void setQuestion(Questions question) {
		this.question = question;
	}

	public Collection<ExamsItems> getExamItemsList() {
		return examItemsList;
	}

	public void setExamItemsList(Collection<ExamsItems> examItemsList) {
		this.examItemsList = examItemsList;
	}

	public int compareTo(Items o) {
		return  (o == this)? 0 : 1;
	}
	
	@Override
	public boolean equals(Object obj) {		
		return ( ((Items)obj).getId()== this.getId());
	}
	
	
}
